<%= javascript_include_tag 'toggler.js' %>

<div id= "<%= row_name + "_expanded" -%>" style="display: <%= hidden ? "none":"inline" -%>">
  <div>
	<% if item.is_archived? %>
    	<ul class="faux_table_archived">
	<% else %>
	   	<ul class="faux_table<%= curr_cycle %>">
	<% end %>
      <li>
		<% if item.is_archived? %>
		<div class="col1"><%= check_box_tag "variable_ids[]", item.id,false, :class=>'variable_checkbox',:disabled=>true,:id=>"#{row_name + '_expanded_checkbox'}" -%></div>
        <div class="col2"><%= image_tag("folds/fold.png", :title=>"Hide details...",:alt=>"Hide details...", :border => 0, :onclick=>"javascript: Element.hide($('#{row_name + '_expanded'}'));Element.show($('#{row_name}'));") -%></div>
		<% else %>
		<div class="col1"><%= check_box_tag "variable_ids[]", item.id,false, :class=>'variable_checkbox', :onclick => "setTrueOrFalse()",:id=>"#{row_name + '_expanded_checkbox'}" -%></div>
        <div class="col2"><%= image_tag("folds/fold.png", :title=>"Hide details...",:alt=>"Hide details...", :border => 0, :onclick=>"javascript:if ($('#{row_name + '_expanded_checkbox'}').checked == true) {$('#{row_name + '_checkbox'}').checked =true} else {$('#{row_name + '_checkbox'}').checked=false};Field.disable('#{row_name + '_expanded_checkbox'}');Field.enable('#{row_name + '_checkbox'}');Element.hide($('#{row_name + '_expanded'}'));Element.show($('#{row_name}'));") -%></div>
		<% end %>
	<% if item.is_archived? %>
	<% if item.name.size > 20 -%>
      <div class="col3"><%= link_to(item.hyphenName, variable_path(item), :title=>item.name) -%>(Archived)</div>
    <% else -%>
      <div class="col3"><%= link_to(item.name, variable_path(item)) -%>(Archived)</div>
    <% end -%>
	<% else %>
	<% if item.name.size > 20 -%>
      <div class="col3"><%= link_to(item.hyphenName, variable_path(item), :title=>item.name) -%></div>
    <% else -%>
      <div class="col3"><%= link_to(item.name, variable_path(item)) -%></div>
    <% end -%>
	<% end %>
 
        <div class="col4">
          <% if item.value != nil -%>
            <%= item.value -%>
          <% else -%>
            <%= "NO DESCRIPTION" -%>
          <% end -%>
        </div>
        <div class="col5">
          <% if item.category != nil -%>
            <%= link_to(item.category, by_category_variables_url(:category=>item.category),:title=>"Show all variables with this category") -%>
          <% else -%>
            <%= "NO CATEGORY" -%>
          <%  end -%>
        </div>
        <div class="col6"><%= dataset.survey.survey_type.shortname -%></div>
        <div class="col7"><%= link_to dataset.name, dataset_url(dataset) -%></div>
        <div class="col8"><%= dataset.survey.year -%> </div>
	 <div class="col9">
        <%= popularity -%>
      </div>
</li>
    </ul>
  </div>
  <% if item.name.size > 20 -%>
    <div style="margin:auto;">Actual Variable name: <%= item.name -%></div>
    <br/>
  <% end -%>
<% if lineage %>
  <div>
	Lineage of term (ie. where/why you added it to your cart) - <%= display_lineage_for_variable(item.id, extract_lineage, extract_id) %>
  </div>
<br/>
<% end %>
  <div>
    <% unless item.document.blank? -%>
      <div style="margin:auto;">Document: 
        <%= link_to(item.document + ", page " + item.page, open_pdf_variable_url(item) + "#page=" + item.page,:title=>"Open the PDF document with information about this variable") -%>
      </div>
    <% else -%>
      <div style="margin:auto;color:red;">No documentation listed</div>
    <% end -%>
  </div>
  <br/>
  <div>
    <% if item.category != nil -%>
      <div style="margin:auto;">Category: <%= item.category -%></div>
    <% else -%>
      <div style="margin:auto;color:red;">No category recorded for this variable</div>
    <% end -%>
  </div>
  <br/>
  <div>
    <% unless item.dertype.blank? -%>
      <div style="margin:auto;">Variable source: <%= item.dertype %></div>
    <% else -%>
      <div style="margin:auto;color:red;">No source</div>
    <% end -%>
  </div>
  <br/>
  <div>
    <% unless item.dermethod.blank? -%>
      <div style="margin:auto;">Derivation method:</div>
      <div style="margin:auto;border:0.2em solid #ACCBE0;"><pre><%=  item.dermethod -%></pre></div>
    <% else -%>
      <div style="margin:auto;color:red;">No derivation method recorded for this variable</div>
    <% end -%>
  </div>
  <br/>
  <div>
    <% if item.info != nil -%>
      <div style="margin:auto;">Allowed values:</div>
      <div style="margin:auto;border:0.2em solid #ACCBE0;"><pre><%= item.info -%></pre></div>
    <% else -%>
      <div style="margin:auto;color:red;">No value information recorded for this variable</div>
    <% end -%>
  </div>
  <!-- <%= item.name %> -->
<% no_var_hash = item.none_values_hash -%> 
<% var_hash = item.values_hash -%>
<% value_domain_hash = Hash.new %>
<% var_hash.each_key do |key| %>
	<% item.value_domains.each do |value_domain| %>
		<% if value_domain.value.to_i.eql?(key.to_i) %> 
			<% value_domain_hash[key] = value_domain.label %>
			<% break %>
		<% end %>
	<% end %>
<% end %>
<% no_var_hash.each_key do |key| %>
	<% item.value_domains.each do |value_domain| %>
		<% if value_domain.value.to_i.eql?(key.to_i) %> 
			<% value_domain_hash[key] = value_domain.label %>
			<% break %>
		<% end %>
	<% end %>
<% end %>
<% if var_hash.size > 0 && var_hash.size <= 20 -%>
<div class="left" id='<%= row_name + "_expanded_stats_chart" -%>'>

	</div>
<% end %>
<div>
  <%= render :partial => "variables/statistics_table",:locals=>{:variable => item} %> 
</div>
<% if var_hash.size > 20 -%>
<div style="font-style: italic; ">(Too many values to display in chart)</div>
<% end %>
<div style="clear:both">
</div>

  <br/>


</div>

<script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      function draw<%= row_name + "_expanded_stats_chart" -%>Chart() {
		var hash_size = <%=var_hash.size %>
		if (hash_size > 1 && hash_size <= 20) {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Value');
        data.addColumn('number', 'Count');
              <% var_hash.sort.each do |value, frequency| -%>
				data.addRow(['<%= value_domain_hash[value] ? escape_javascript(value_domain_hash[value].to_s) : escape_javascript(value.to_s) %>', <%= frequency %>]);
				              <% end -%>
							              <% no_var_hash.sort.each do |value, frequency| -%>
							data.addRow(['<%= value_domain_hash[value] ? escape_javascript(value_domain_hash[value].to_s) : escape_javascript(value.to_s) %>', <%= frequency %>]);
							              <% end -%>

        var chart = new google.visualization.PieChart(document.getElementById('<%= row_name + "_expanded_stats_chart" -%>'));
        chart.draw(data, {width: 400, height: 200, is3D: true});
	}
      }
    </script>
